// 创建一个新的WebSocket实例
const socket = new WebSocket('ws://localhost:11222/ws');
 
// 当WebSocket连接打开时触发
socket.onopen = function(event) {
  console.log('WebSocket success');
};
 
// 当WebSocket接收到服务器发送的消息时触发
socket.onmessage = function(event) {
  console.log('receive:', event.data);
};
 
// 当WebSocket连接关闭时触发
socket.onclose = function(event) {
  console.log('WebSocket closed');
};
 
// 当WebSocket通信发生错误时触发
socket.onerror = function(error) {
  console.error('WebSocket err:', error);
};
 